package com.arcsoft.crud.limitNumber.task;

import java.util.Date;
import java.util.Map;

import com.arcsoft.crud.Constants.Global;
import com.arcsoft.crud.limitNumber.base.BenchmarkBase;
import com.arcsoft.crud.limitNumber.base.BenchmarkTask;
import com.arcsoft.crud.util.ConnectionDB;
import com.arcsoft.log.entity.OptimizeAnalyzeLog;

public class UpdateTask extends BenchmarkTask{

	public UpdateTask(int threadIndex, BenchmarkBase parent,
			int printInfoInterval, long loopCount, String taskLogTable) {
		super(threadIndex, parent, printInfoInterval, loopCount, taskLogTable);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public String execute(int loopIndex){
        ConnectionDB db = new ConnectionDB();
        Map<String, Long> map = prepareData();
        
        String sql = "update people set password = ? where id = ?";
         
        long startId =map.get("startId");
        long scope = map.get("scope");
        long param =(long)(Math.random()*(map.get("endId")-map.get("startId")))+startId;
        //Object arrays[] = {"james"+threadIndex+""+loopIndex,(threadIndex+1)*loopCount-loopIndex};
        Object arrays[] = {randomString((int)Math.random()*10),param};
         
        int line = db.updateBySql(sql, arrays);
         
        return parseSql(sql, arrays);
	}
	
	@Override
	public void logInfo(Date startTime, Date endTime, String requestDetail, int extendTime){
		
		String sceneDesc = Global.OPERATOR_TYPE_UPDATE+"-"+Global.THREAD_COUNT+"C-"+Global.LOOP_COUNT+"L";//场景名命名规则 操作类型-并发数C-循环次数L
		
		OptimizeAnalyzeLog optimizeAnalyzeLog = new OptimizeAnalyzeLog
					(sceneDesc,Global.OPERATOR_TYPE_UPDATE,startTime, endTime, extendTime, requestDetail);
		
		insertLog(optimizeAnalyzeLog);
	}

}
